package org.eclipse.unofficial.flexitabs;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

/** Utility class for graphics */
public class SwtUtil {
	/** For opening shells */
	public interface GenericShellClient {
		/** The shell has a FillLayout and no title by default. */
		public void addToShell(Shell shell);
	}
	
	/**
	 * Opens a generic shell with the given style bits
	 * and gives the client a chance to add itself to the
	 * shell.
	 */
	public static void openShell(int styleBits, SwtUtil.GenericShellClient tester) {
		Display display = new Display();
		Shell shell = new Shell(display, styleBits);
		shell.setLayout(new FillLayout());

		tester.addToShell(shell);

		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		display.dispose();
	}
	
	/**
	 * Opens a generic shell with the given style bits
	 * and gives the client a chance to add itself to the
	 * shell.
	 */
	public static void openShell(SwtUtil.GenericShellClient tester) {
		openShell(SWT.SHELL_TRIM, tester);
	}
}
